package com.ansion.baseui.base;

import android.app.Activity;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.ansion.baseui.R;
import com.ansion.baseui.base.loading.CustomAlertDialog;
import com.ansion.baseui.base.loading.TLoadingUtil;

/**
 * created by zhaoyuntao
 * on 16/09/2022
 * description:
 */
public interface LoadingSupport {
    default void showLoading() {
        dismissLoading();
        CustomAlertDialog loadingDialog = TLoadingUtil.showLoading(activity(), true, R.string.please_wait);
        onSetLoadingDialog(loadingDialog);
    }

    default void showLoading(@StringRes int textRes) {
        dismissLoading();
        CustomAlertDialog loadingDialog = TLoadingUtil.showLoading(activity(), true, textRes);
        onSetLoadingDialog(loadingDialog);
    }

    default void showLoading(@NonNull CharSequence text) {
        dismissLoading();
        CustomAlertDialog loadingDialog = TLoadingUtil.showLoading(activity(), true, text);
        onSetLoadingDialog(loadingDialog);
    }

    default void showLoading(boolean cancelable) {
        dismissLoading();
        CustomAlertDialog loadingDialog = TLoadingUtil.showLoading(activity(), cancelable);
        onSetLoadingDialog(loadingDialog);
    }

    default void showLoading(@StringRes int textRes, boolean cancelable) {
        dismissLoading();
        CustomAlertDialog loadingDialog = TLoadingUtil.showLoading(activity(), cancelable, textRes);
        onSetLoadingDialog(loadingDialog);
    }

    default void showLoading(@StringRes int textRes, @DrawableRes int drawableRes, boolean cancelable) {
        dismissLoading();
        CustomAlertDialog loadingDialog = TLoadingUtil.showLoading(activity(), cancelable, textRes, drawableRes);
        onSetLoadingDialog(loadingDialog);
    }

    Activity activity();

    CustomAlertDialog getLoadingDialog();

    void onSetLoadingDialog(@Nullable CustomAlertDialog loadingDialog);

    default void dismissLoading() {
        TLoadingUtil.stopLoading(activity(), getLoadingDialog());
        onSetLoadingDialog(null);
    }
}
